package com.apps.ftapp.activity;

import android.view.KeyEvent;

import com.apps.ftapp.MainActivity;
import com.apps.ftapp.R;
import com.apps.ftapp.util.ActivitySkipUtil;
import com.apps.ftapp.util.SharedPreferencesUtil;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;

public class WelcomeActivity extends ABeseActivity {


    private static final int ANIM_TIME = 2000;
    private static final float SCALE_END = 1.15F;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_welcome;
    }

    @Override
    protected void initEventAndData() {
        startMainActivity();
    }

    /*@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        ButterKnife.bind(this);
        *//*
        * // 判断是否是第一次开启应用
        boolean isFirstOpen = SharedPreferencesUtil.getBoolean(this, SharedPreferencesUtil.FIRST_OPEN, true);
        // 如果是第一次启动，则先进入功能引导页
        if (isFirstOpen) {
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();c
            return;
        }
        * *//*

        // 如果不是第一次启动app，则正常显示启动屏
        //显示图片的配置  


        //    loadData();
        //   SharedPreferencesUtil.putBoolean(WelcomeActivity.this, SharedPreferencesUtil.IS_VIP, false);
        startMainActivity();


    }*/


    private void startMainActivity() {
        //ivEntry.setImageResource(R.drawable.welcome);
        addDisposable(Observable.timer(1000, TimeUnit.MILLISECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(aLong -> startAnim()));
    }


    private void startAnim() {
        //   ObjectAnimator animatorX = ObjectAnimator.ofFloat(ivEntry, "scaleX", 1f, SCALE_END);
        //    ObjectAnimator animatorY = ObjectAnimator.ofFloat(ivEntry, "scaleY", 1f, SCALE_END);
        //  AnimatorSet set = new AnimatorSet();
        //   set.setDuration(ANIM_TIME).play(animatorX).with(animatorY);
        //   set.start();
        //    set.addListener(new AnimatorListenerAdapter() {
        //          @Override
        //      public void onAnimationEnd(Animator animation) {

        //默认为true 如果为ture 就是未登录
        boolean isFirstOpen = SharedPreferencesUtil.getBoolean(getApplicationContext(), SharedPreferencesUtil.IS_LOGIN, true);
        if (isFirstOpen) {
            //未授权登录
            ActivitySkipUtil.skipAnotherActivity(WelcomeActivity.this, LoginActivity.class, true);
        } else {
            ActivitySkipUtil.skipAnotherActivity(WelcomeActivity.this, MainActivity.class, true);

        }
    }

    /**
     * 屏蔽物理返回按钮
     *
     * @param keyCode
     * @param event
     * @return
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
